/**
 * @file
 * @auth jinguangguo
 * @date 2017/1/18
 */

import Vue from 'vue';
import tpl from './tpl.html';
import './style.scss';
import Loading from '../../../../../grsc-base/component/Loading.vue';
import service from './service';
import lib from '../../../../common/lib';
import NoData from '../../../../../grsc-base/component/NoData.vue';
import Qrcode from '../../../../../grsc-base/component/Qrcode.vue';
import Pager from '../../../../../grsc-base/component/Pager.vue';
export default Vue.extend({
  name: "recommend",
  template: tpl,
  components: {
    Loading,
    NoData,
    Qrcode,
    Pager
  },

  data() {
    return {
      code: '',
      isLoading: true,
      list: [],
      isLoadings: true,
      address: '',
      countryList: ['我的好友', '我的团队'],
      lib,
      pageNum: 0,
      types:'我的好友',
      codes:'',
      param: {
        pageNo:1,
        pageSize:10,
      }
    }
  },
  created() {
    this.getInviteCode();
    this.getUserCode();
  },
  watch: {
    types(val) {
      console.log(val)
      if (val == '我的好友') {
        this.getUserCode()
        return false
      }
      if (val == '我的团队') {
        this.getMember()
        return false
      }
    }
  },
  filters: {
    formatPhone: function (phone) {
      return phone.substr(0, 3) + '****' + phone.substr(7, 11);
    }
  },
  mounted() {},
  methods: {
    //查看我邀请的人
    getUserCode() {
      service.UserCode(this.param).done(data => {
        if (data.code == window.CODE.SUCCESS) {
          this.list = data.data.list
          this.isLoadings = false;
          this.pageNum = data.data.pageNum;
        } else {
          window.error(data.msg)
        }
      })
    },
    //翻页
    changePage(val) {
      this.param.pageNo = val;
      this.selectUserLockInfoByRules();
    },
    getMember() {
      service.getMember(this.param).done(data => {
        if (data.code == window.CODE.SUCCESS) {
          this.list = data.data.list;
          this.pageNum = data.data.pageNum;
          this.isLoadings = false;
        } else {
          window.error(data.msg)
        }
      })
    },
    //获取个人推荐码
    getInviteCode() {
      service.getInviteCode().done(data => {
        console.log(data);
        if (data.code == window.CODE.SUCCESS) {
          this.code = data.data
          this.isLoading = false;
          let url = window.location.href;
          let register = '';
          if (url.indexOf('smt-ex.com') > -1) {
            register = 'http://smt-ex.com/#/pages/register/register?code='+this.code
            this.codes = 'http://smt-ex.com/#/pages/register/register?code='+this.code
          } else if (url.indexOf('smt-ex.com') > -1) {
            register = 'http://smt-ex.com/#/pages/register/register?code='+this.code
            this.codes = 'http://smt-ex.com/#/pages/register/register?code='+this.code
          } else if (url.indexOf('localhost') > -1) {
            register = 'http://smt-ex.com/#/pages/register/register?code='+this.code
            this.codes = 'http://smt-ex.com/#/pages/register/register?code='+this.code
          }
          this.address = register;
        } else {
          window.error(data.msg)
        }
      }).fail(err => {
        window.error(err.msg)
      })
    },
    copy(e) {
      lib.copy($(e));
    }
  },
});